package com.example.medical.controller;

import com.example.medical.domain.Shop;
import com.example.medical.service.ShopService;
import  com.example.medical.service.ShopService;
import  com.example.medical.util.AjaxResuit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop")
@Api(tags = "店铺管理（0525王婕）")
public class ShopController {

    @Autowired
    ShopService service;

    // 获取所有店铺列表
    @GetMapping("/getShopListAll")
    @ApiOperation(value = "获取店铺列表")
    public AjaxResuit getShopListAll() {
        System.out.println(service.selectAll());
        return AjaxResuit.success(service.selectAll());
    }

    // 根据店铺id查询店铺信息
    @GetMapping("/getShopById")
    @ApiOperation(value = "根据id查询店铺信息")
    public AjaxResuit getShopById(int id) {
        System.out.println(service.selectById(id));
        return AjaxResuit.success(service.selectById(id));
    }

    // 新增店铺
    @PostMapping("/addShop")
    @ApiOperation(value = "新增店铺")
    public AjaxResuit addShop(@RequestBody Shop shop) {
        return AjaxResuit.success(service.saveShop(shop));
    }
    // 更新店铺信息接口，接收更新后的店铺对象，调用Service层方法进行更新操作并返回相应结果
    @PutMapping("/updateShop")
    @ApiOperation(value = "更新店铺信息")
    public AjaxResuit updateShop(@RequestBody Shop shop) {
        int result = service.updateShop(shop);
        if (result > 0) {
            return AjaxResuit.success("店铺信息更新成功");
        } else {
            return AjaxResuit.error("店铺信息更新失败");
        }
    }

    // 删除店铺接口，根据传入的店铺id调用Service层方法删除对应店铺，并返回相应结果
    @DeleteMapping("/deleteShop")
    @ApiOperation(value = "删除店铺")
    public AjaxResuit deleteShop(int id) {
        int result = service.deleteShop(id);
        if (result > 0) {
            return AjaxResuit.success("店铺删除成功");
        } else {
            return AjaxResuit.error("店铺删除失败");
        }
    }


    // 店铺登录（假设存在这样的逻辑需求，比如后台管理登录等情况，可按实际调整）
    @PostMapping("/ShopLogin")
    @ApiOperation(value = "店铺登录")
    public AjaxResuit ShopLogin(Shop shop) {
        return AjaxResuit.success(service.checkShop(shop));
    }
}